package com.xingxing.service.impl;

import com.xingxing.entity.CostRecord;
import com.xingxing.entity.GroupByMonthEntity;
import com.xingxing.entity.LogEntity;
import com.xingxing.mapper.LogMapper;
import com.xingxing.service.LogService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: 小白一号
 * @date: 2022/11/17
 * @desc:
 */
@Transactional  //事务注解,自动开启事务
@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private LogMapper logMapper;

    @Override
    public List<LogEntity> findAll() {
        return logMapper.findAll();
    }

    @Override
    public LogEntity findByCardId(@Param("cardId") String cardId) {
        return logMapper.findByCardId(cardId);
    }

    @Override
    public int updateLog(String userCardId, float cost, String date) {
        Map<String, Object> map = new HashMap();
        map.put("userCardId", userCardId);
        map.put("cost", cost);
        map.put("logDate", date);
        return logMapper.updateLog(map);
    }

    @Override
    public List<GroupByMonthEntity> groupByMonth(String userAccount) {
        return logMapper.groupByMonth(userAccount);
    }

    @Override
    public List<CostRecord> findDailyCostByUserAccount(Map<String, Object> map) {
        return logMapper.findDailyCostByUserAccount(map);
    }

    @Override
    public List<CostRecord> findMonthCostByUserAccount(Map<String, Object> map) {
        return logMapper.findMonthCostByUserAccount(map);
    }
}
